import MySQLdb
from django.http import HttpResponse
from django.shortcuts import render


# Create your views here.
def book_list(request):
    # 省略了port=3306
    db = MySQLdb.connect(user='root', db='mysite2', passwd='DongNao123@', host='192.168.222.11', charset='utf8')
    cursor = db.cursor()
    cursor.execute('SELECT title FROM books_book ORDER BY title')
    names = [row[0] for row in cursor.fetchall()]
    db.close()
    return render(request, 'books/book_list.html', {'names': names})


def display_meta(request):
    values = request.META.items()
    # values.sort()
    html = []
    for k, v in values:
        html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v))
    return HttpResponse('<table>%s</table>' % '\n'.join(html))
